<include file="Public:head" />
<div class="col-xs-12">
    <div class="tabbable">
        <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab">
            <li class="active">
                <a href="#home" data-toggle="tab">配置列表</a></li>
            <li>
        </ul>
        <div class="tab-content">
            <table class="layui-table">
                <tr>
                    <th>配置名称</th>
                    <th>配置值</th>
                    <th>配置描述</th>
                    <th>修改时间</th>
                    <th>操作</th>
                </tr>
                <volist name="list" id="vo">
                    <tr>
                        <td>
                            <input type="text" id="name_{$vo.config_id}" placeholder="请输入配置名称" value="{$vo.config_name}" class="layui-input" >
                        </td>
                        <td>
                            <input type="text" id="value_{$vo.config_id}" placeholder="请输入配置值" value="{$vo.config_value}" class="layui-input" >
                        </td>
                        <td>
                            <input type="text" id="remark_{$vo.config_id}" placeholder="请输入配置描述" value="{$vo.config_remark}" class="layui-input" >
                        </td>
                        <td>
                            {$vo.config_time|date='Y-m-d H:i:s',###}
                        </td>
                        <td width="120">
                            <a href="javascript:;" onclick="upd({$vo.config_id})" class="confirm ajax-get layui-btn layui-btn-mini">修改</a>
                            <a href="javascript:;" onclick="del('{:U('delconfig')}',{$vo.config_id})" class="confirm ajax-get layui-btn layui-btn-mini layui-btn-danger">删除</a>
                        </td>
                    </tr>
                </volist>
                <tr>
                    <td>
                        <input id="config_name" type="text" size="50" value="" placeholder="请输入新配置名称" class="layui-input" >
                    </td>
                    <td>
                        <input id="config_value" type="text" size="50" value="" placeholder="请输入新配置值" class="layui-input" >
                    </td>
                    <td>
                        <input id="config_remark" type="text" size="50" value="" placeholder="请输入新配置描述" class="layui-input" >
                    </td>
                    <td></td>
                    <td>
                        <a href="javascript:;" onclick="add()" class="confirm ajax-get layui-btn layui-btn-small layui-btn-normal">添加</a>
                    </td>
                </tr>     
            </table>
            <div class="panel-footer ft clearfix">
                <div class="pull-left">
                    
                </div>
                <div class="layui-laypage layui-laypage-default pull-right">
                    {$page}
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript"> 
    function add(){
        var config_name = $('#config_name').val();
        var config_value = $('#config_value').val();
        var config_remark = $('#config_remark').val();

        if(config_name == '' || config_value == '' || config_remark == ''){
            alert('新增配置项数据不完整！');
            return;
        }
        
        $.ajax({
            url:'{:U("addconfig")}',//跳转到action
            data:{
                config_name : config_name,
                config_value : config_value,
                config_remark : config_remark
            },
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data){
                if(data.status==1){
                    layer.msg(data.info, {icon: 6,shade: 0.2,time:1000}, function(){
                        location.href = data.url;
                    });
                }else{
                    layer.msg(redata.info, {icon: 5,shade: 0.2,time:1200});
                }
             },
            error:function(){
                layer.msg('网络错误，请刷新后重试！', {icon: 0,shade: 0.2,time:1200});
            }
        });
    }
    
    function upd(id){
        if(confirm('您确定修改该条配置吗？')){
            var config_id = id;
            var config_name = $('#name_'+ id).val();
            var config_value = $('#value_'+ id).val();
            var config_remark = $('#remark_'+ id).val();

            if(config_name == '' || config_value == '' || config_remark == ''){
                alert('修改配置项数据不完整！');
                return;
            }
            
            $.ajax({
                url:'{:U("updconfig")}',//跳转到action
                data:{
                    config_id : config_id,
                    config_name : config_name,
                    config_value : config_value,
                    config_remark : config_remark
                },
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.info, {icon: 6,shade: 0.2,time:1000}, function(){
                            location.href = data.url;
                        });
                    }else{
                        layer.msg(redata.info, {icon: 5,shade: 0.2,time:1200});
                    }
                 },
                error:function(){
                    layer.msg('网络错误，请刷新后重试！', {icon: 0,shade: 0.2,time:1200});
                }
            });
        }
    }
</script>
<include file="Public:foot" />